package com.york.oss.controller;

import com.york.oss.service.OssService;
import com.york.utils.exception.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Description:讲师头像上传
 * @Data: 2022/3/10 16:47
 * @Author: yangboxiong
 * @Version
 * @since JDK 1.8
 */
@Api(tags = "阿里云文件管理")
@RestController
@RequestMapping("/eduoss/fileoss")
public class OssController {

    @Autowired
    private OssService ossService;

    /**
     * OSS头像上传
     *
     * @param file
     * @return
     */
    @ApiOperation("文件上传")
    @PostMapping("/upload")
    public R uploadOssFile(
            @ApiParam(value = "文件", required = true)
            @RequestParam("file") MultipartFile file) {
        String uploadUrl = ossService.uploadFileAvatar(file);
        //返回r对象
        return R.ok().message("文件上传成功").data("url", uploadUrl);
    }
}
